##  This file contains the code to replicate the analyses reported in Table SI-9
##

rm(list = ls(all.names = TRUE))
library(Hmisc)
library(lmtest)
library(sandwich)
library(pscl)
library(MASS)
library(mice)
library(miceadds)
library(openxlsx)


#setwd("~/Dropbox/Current projects/Nazi trials/analysis")
load("Nazi trials replication data.RData")
file.info("Nazi trials replication data.RData")$mtime

##  source helper functions
source("probit2.r")



##
##  Estimate models and save the results
##  Also conduct Monte Carlo simulations of first differences
tab1 <- matrix("",29,6)
colnames(tab1) <- paste0("(",1:ncol(tab1),")")

rownames(tab1) <- c(
					"% judges who were appointed in 1933--45", "",
					"% judges who were appointed pre-1933", "",
					"% judges who completed legal training in 1933--45", "",
					"% judges who completed legal training pre-1933", "",
					"avg. share of judges' legal education in 1933--45", "",
					"avg. share of judges' legal education pre-1933", "",
					"% prosecutors who were appointed in 1933--45", "",
					"% prosecutors who were appointed pre-1933", "",
					"% prosecutors who completed legal training in 1933--45", "",
					"% prosecutors who completed legal training pre-1933", "",
					"avg. share of prosecutors' legal education in 1933--45", "",
					"avg. share of prosecutors' legal education pre-1933", "",
					"Year FE","State FE", "Crime categorization FE",
					"$p$-value Wald test % judges","$p$-value Wald test % prosecutors")

sims.tab <- vector(mode = "list", length = 6)


##  add additional predictors?
add.pred <- " + state"	#  state FEs; all models include crime categories and year FEs



##  col 3
add.pred.MI <- c("NS_judge_@_2","NS_prosecutor_@_2")

##  probit
out <- glm.MI(d = cases.temp, outcome = "convicted", add.pred.MI = add.pred.MI, add.pred = add.pred,
sims = 1, wald = NULL)
tab1[c(5,17),3] <- out[[1]][2:3,1]
tab1[c(6,18),3] <- out[[1]][2:3,2]
sims.tab[[3]][1] <- list(out[[3]])

##  first difference (reported in note at bottom of table):
round(out[[3]][1],2)



##  col 4
add.pred.MI <- c("NS_judge_@_2","NS_prosecutor_@_2","NS_judge_@_5","NS_prosecutor_@_5")

##  probit
out <- glm.MI(d = cases.temp, outcome = "convicted", add.pred.MI = add.pred.MI, add.pred = add.pred,
sims = 1, wald = list(c(1,3),c(2,4)))
tab1[c(5,17,7,19),4] <- out[[1]][2:5,1]
tab1[c(6,18,8,20),4] <- out[[1]][2:5,2]
tab1[28,4] <- out[[2]][1]
tab1[29,4] <- out[[2]][2]
sims.tab[[4]][1] <- list(out[[3]])

##  first difference (reported in note at bottom of table):
round(out[[3]][1],2)



##  add checkmarks to table
tab1[25:27,1:6]	<- "\\checkmark"


##  extract only the relevant parts of the results table
tab1[c(5:8,17:20,25:29),3:4]

latex(tab1[c(5:8,17:20,25:29),3:4], file = "")


sessionInfo()






.
